home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / libiberty / memcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.4 KB  |  58 lines

  1. /* memcmp -- compare two memory regions.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18.  
  19. /*
  20.  
  21. NAME
  22.  
  23.     memcmp -- compare two memory regions
  24.  
  25. SYNOPSIS
  26.  
  27.     int memcmp (const void *from, const void *to, size_t count)
  28.  
  29. DESCRIPTION
  30.  
  31.     Compare two memory regions and return less than,
  32.     equal to, or greater than zero, according to lexicographical
  33.     ordering of the compared regions.
  34. */
  35.  
  36. #include <ansidecl.h>
  37. #ifdef __STDC__
  38. #include <stddef.h>
  39. #else
  40. #define size_t unsigned long
  41. #endif
  42.  
  43. int
  44. DEFUN(memcmp, (str1, str2, count),
  45.       PTRCONST str1 AND PTRCONST str2 AND size_t count)
  46. {
  47.   register unsigned char *s1 = (unsigned char*)str1;
  48.   register unsigned char *s2 = (unsigned char*)str2;
  49.  
  50.   while (count-- > 0)
  51.     {
  52.       if (*s1++ != *s2++)
  53.       return s1[-1] < s2[-1] ? -1 : 1;
  54.     }
  55.   return 0;
  56. }
  57.  
  58.